<script setup>
import { ref } from 'vue';
const paymentPopup=ref(null)

const close=()=>paymentPopup.value.close()
const open=()=>paymentPopup.value.open()

// 选择支付方式
const paymentchannel=[
	{
	title:'微信支付',
	thumb:'/static/wx.png',
	},
	{
	title:'支付宝支付',
	thumb:'/static/zfb.png'	
	}
]
// 选择的支付方式
const channelIndex=ref(0)
const onChannelChange=(index)=>{
	  channelIndex.value=index
	  emit('changepay',index)
}

const paymentProps=defineProps({
	amount:String,
	OrderID:{
		type:[Number,String],
		default:0
	},
})


const emit=defineEmits(['changepay','payclose','payconfirm'])

defineExpose({
	close,
	open
})
</script>

<template>
  <uni-popup
    :is-mask-click="false"
    ref="paymentPopup"
	type="bottom"
    @maskClick="$emit('payclose')"
  >
    <view class="payment-container">
      <view class="payment-header">
        <text class="title">选择支付方式</text>
        <uni-icons
          class="uni-icons-close"
          size="18"
          color="#333"
          type="closeempty"
          @click="$emit('payclose')"
        />
      </view>
      <view class="order-amount">¥ {{ paymentProps.amount }}</view>
      <uni-list :border="false">
        <uni-list-item
          v-for="(channel, index) in paymentchannel"
          :key="channel.title"
          :title="channel.title"
          :thumb="channel.thumb"
          clickable
          @click="onChannelChange(index)"
        >
          <template #footer>
            <!-- size 要是数字，绑定时要加冒号，不然就是字符串不生效 -->
            <uni-icons
              v-if="channelIndex === index"
              :size="26"
              color="#16C2A3"
              type="checkbox-filled"
            />
            <uni-icons v-else :size="26" color="#d1d1d1" type="circle" />
          </template>
        </uni-list-item>
      </uni-list>
      <button
        @click="$emit('payconfirm', { index: channelIndex })"
        class="uni-button"
      >
        立即支付
      </button>
    </view>
  </uni-popup>
</template>


<style lang="scss">
  .payment-container {
    min-height: 400rpx;
    border-radius: 30rpx 30rpx 0 0;
    background-color: #fff;
    padding: 10rpx 30rpx 40rpx;

    .payment-header {
      height: 88rpx;
      line-height: 88rpx;
      text-align: center;
      margin-bottom: 20rpx;
      font-size: 32rpx;
      color: #333;
      position: relative;
    }

    .uni-icons-close {
      position: absolute;
      top: 2rpx;
      right: 0;
    }

    .order-amount {
      padding: 10rpx 0 10rpx;
      text-align: center;
      font-size: 40rpx;
      color: #333;
    }

    :deep(.uni-list-item__container) {
      padding: 40rpx 0 !important;
    }

    :deep(.uni-list-item--hover) {
      background-color: #fff !important;
    }

    :deep(.uni-list-item__icon) {
      margin-right: 0;
    }

    .uni-button {
      margin-top: 40rpx;
    }
  }
</style>